﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace BEELab
{
    public partial class ExperimentManagement : System.Web.UI.Page
    {
        /// <summary>
        /// Occures on every page load (first time or Post Back)
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["Admin"] == null || (bool)Session["Admin"] == false)
            {
                gvExperiment.Columns[3].Visible = false;
            }
        }

        /// <summary>
        /// Creates and inserts new experiment to DB, according to details that inserted by the user
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            BEELab.Logic.ProgramManagement.ExperimentManagement.CreateExperiment(txtName.Text, txtDescription.Text, int.Parse(Session["UserID"].ToString()), true);
            gvExperiment.DataBind();
        }

        /// <summary>
        /// Occures once use is pressing on deleting current experiment from DB
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void gvExperiment_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            BEELab.Logic.ProgramManagement.ExperimentManagement.DeleteExperiment(Convert.ToInt32(gvExperiment.DataKeys[e.RowIndex].Value));
        }
    }
}